package 第二周.第四课;

/*
 * @author  YxinMiracle
 * @date  2022-04-26 11:24
 * @Gitee: https://gitee.com/yxinmiracle
 */

public class 两数之和2 {

    public int[] twoSum(int[] numbers, int target) {
        // 双指针算法
        int j = numbers.length - 1;
        for (int i = 0; i < numbers.length; i++) {
            while (i < j && numbers[i] + numbers[j] > target) j--;
            if (i < j && numbers[i]+numbers[j] == target){
                return new int[]{i+1,j+1};
            }
        }
        return null;
    }
}
